package com.ruoyi.quartz.task;

import com.ruoyi.coupons.service.ICouponsMemberService;
import com.ruoyi.coupons.service.ICouponsService;
import com.ruoyi.order.service.IStoreProductOrderHandleService;
import com.ruoyi.order.service.IStoreProductOrderService;
import com.ruoyi.product.service.IStoreProductBackService;
import com.ruoyi.product.service.IStoreProductService;
import com.ruoyi.withdraw.service.IWithdrawApplyHandleService;
import com.ruoyi.withdraw.service.IWithdrawApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author chengliang
 * @date 2021/11/30
 **/
@Component("orderTask")
public class OrderTask {
    @Autowired
    private IStoreProductOrderService orderService;
    @Autowired
    private IStoreProductOrderHandleService handleService;
    @Autowired
    private ICouponsService couponsService;
    @Autowired
    private ICouponsMemberService couponsMemberService;
    @Autowired
    private IStoreProductBackService productBackService;
    @Autowired
    private IStoreProductService productService;
    @Autowired
    private IWithdrawApplyHandleService wHandleService;
    @Autowired
    private IWithdrawApplyService applyService;
    //结算任务
    public void billingTask()
    {
     if(true){
         return;
     }
        //查询需要结算的订单
      /*  List<Long> ids = new ArrayList<>();//orderService.selectNeedBilling();sql有问题
        if(ids.size()==0)
            return;
        ids.forEach( e-> {
            List<StoreProductOrder> orders = orderService.selectListByStoreId(e);
            BigDecimal total = new BigDecimal("0");

            WithdrawApply apply = new WithdrawApply();
            apply.setStoreId(e);
            for (StoreProductOrder o:orders) {
                total = total.add(o.getPayPrice().multiply(o.getCommissionPercent()));
                o.setBillingState(DicConstants.BILLING_STATE_In.getCode());
                o.setBillingTime(new Date());
                orderService.updateStoreProductOrder(o);
            }
            apply.setPayOrderNo(OrderNoUtil.getOrderNo(e));
            apply.setWithdrawMoney(total);
            apply.setWithdrawName("系统自动提现");
            apply.setWithdrawState(DicConstants.WITHDRAW_STATE_In_Remit.getCode());
            applyService.insertWithdrawApply(apply);
            WithdrawApplyHandle handle = new WithdrawApplyHandle();
            handle.setHandleName("定时任务提现");
            handle.setWithdrawApplyId(apply.getId());
            wHandleService.insertWithdrawApplyHandle(handle);
        });*/
    }
}
